var systemInterfaceParam=null;
$(document).ready(function(){
	$(".button_con a" ).removeClass("l-btn-plain");
	
	//所属领域下拉框
		$('#comboxSearchfieldName').combobox({
			url: BASE_URL_FIELD_SEARCH + '/findAllOfCurrentUserCanManage' + '?v=' + Math.random(),
			valueField: 'id',
		    textField: 'name',
		    editable: false,
		    method:'get',
		    loadFilter: function(data){
		    	var allCheck = {'id':'','name':'全部'};
		    	data.content.unshift(allCheck);
		    	return data.content;
		    },
		    onSelect: function(record){
		    	comboxSearchSystemName.combobox({
                  disabled: false,
                  method:'get',
                  queryParams: {fieldId: record.id},
                  url: BASE_URL_FIELD_SYSTEM_SEARCH +'/findByFieldOfCurrentUserCanManage' + '?v=' + Math.random(),
                  valueField: 'id',
                  textField: 'name',
				  data:'',
      		    loadFilter: function(data){
      		    	var allCheck = {'id':'','name':'全部'};
      		    	data.content.unshift(allCheck);
      		    	return data.content;
      		    },
      		    onLoadSuccess:function(){
      		    	comboxSearchSystemName.combobox('setValue','');
      		    }
              }).load();
		    },
		    onLoadSuccess:function(){
		    	$('#comboxSearchSystemName').combobox('setValue','');
		    }
		});
		
		//所属系统下拉框
		var comboxSearchSystemName = $('#comboxSearchSystemName').combobox({
          disabled: true,
          valueField: 'id',
          textField: 'name',
          editable: false,
		  data:[{id:'',name:'全部','selected':'true'}]
      });
	
	$("#datagrid").datagrid({
			url :'/api/interfaceCounts/search/findByExample' + '?v=' + Math.random(),
			method:'get',
			autoRowHeight:true,
			nowrap:false,
			singleSelect:true,
			striped:true,
			pageSize:20,
			pagination:true,
			pageList:[10,20,50,100],
			columns:[[
						{field:'fieldName',title:'领域',width:100},
						{field:'systemName',title:'系统',width:100},
						{field:'interfaceName',title:'接口名称',width:100},
						{field:'totalAmount',title:'总执行次数(次)',width:100,formatter:function(value,rowData,rowIndex){
							return rowData.successTimes + rowData.failedTimes
						}},
						{field:'recordQTY',title:'传输数据量(条)',width:100},
						{field:'successTimes',title:'成功次数(次)',width:100},
						{field:'failedTimes',title:'失败次数(次)',width:100},
						{field:'successPercent',title:'成功率',width:100, formatter: function(value, rowData, rowIndex){
							return Math.round(rowData.successTimes/(rowData.failedTimes + rowData.successTimes) * 10000)/100 + "%"
						}}
			      ]],
			onSelect:function(rowIndex,rowData){
				$("#toolbar_edit").linkbutton('enable');
				$("#toolbar_delete").linkbutton('enable');
				$(this).datagrid('unselectRow', rowIndex);
			},
			loadFilter:function(data){
				return {
					total: data.totalElements,
					rows: data.content
				};
			},
			onBeforeLoad:function(param){
				param.page -= 1;
				param.size = param.rows;
				delete param.rows;
				
				param.sort = 'createTime,desc';
				
				var interfaceName = $("#interfaceName").val();
				if(interfaceName != ""){
					param.interfaceName = interfaceName;
				}
				
				var fieldName = $('#comboxSearchfieldName').combobox('getText');
				if(fieldName !="全部"){
					param.fieldName = fieldName;
				}
				
				var fieldSystemName = $('#comboxSearchSystemName').combobox('getText');
				if(fieldSystemName !="全部"){
					param.systemName = fieldSystemName;
				}
				
				systemInterfaceParam = param;
			}
		});
		
	$("#datagrid").datagrid('getPager').pagination({   
		displayMsg:'当前显示从 [{from}] 到 [{to}] 共[{total}]条记录'
	}); 
	

	
	
	//导出
	$('#report').window({
		width:465,
		modal:true,
		minimizable:false,
		maximizable:false,
		collapsible:false
	});
	$('#report').window('close');  //关闭窗口
});

	
	//导出操作
	function report()
	{
		$('#datagrid').datagrid({
			url:'/api/interfaceCounts/search/findByExample' + '?v=' + Math.random()
		});
		var param = JSON.stringify(systemInterfaceParam);
		location.href= BASE_URL_EXPORTDATA_FILE + '/implementedInterfaceCountExport?param='+param;
	}
	
	//查询
	function onSearch(){
		$("#datagrid").datagrid("reload", '/api/interfaceCounts/search/findByExample?v=' + Math.random());	
	}